function pH=ecogStackedTSPlot(ecog,trialNum,nThChanneltoPlot)
%pH=ecogStackedTSPlot(ecog,trialNum) plot time series stacked in one column
%
% INPUT:
% ecog:     An ecog structure
% trialNum: The number of the trial to plot
% nThChannelToPlot: if passed only nTh channel will be plotted. Otherwise
% every channel
% 
% OUTPUT:
% pH:       An array of plot handles
%

% 090109 JR wrote it

if ~exist('nThChanneltoPlot','var') || isempty(nThChanneltoPlot)
    nThChanneltoPlot=1;
end

scaleFac=var(ecog.data(:,:,trialNum),0,2);
scaleVec=[1:length(ecog.selectedChannels)]'*max(scaleFac)*1/50; %The multiplier is arbitrary. Find a better solution
tmp=squeeze(ecog.data(ecog.selectedChannels,:,trialNum))+repmat(scaleVec,1,size(ecog.data,2));
%A line indicating zero for every channel
%line(repmat([ecog.timebase(1);ecog.timebase(end)],1,length(scaleVec)),[scaleVec';scaleVec'],'color','k');
hold on;
size(tmp(1:nThChanneltoPlot:end,:))
pH=plot(ecog.timebase,tmp(1:nThChanneltoPlot:end,:));
%pH(end+1)=line([0 0],[min(tmp(:)) max(tmp(:))],'color','k');
axis tight
